<script lang="ts" setup>
import HomePanel from './HomePanel.vue'
import useStore from '@/store'
import { useLazyData } from '@/utils/hooks';

const { home } = useStore()


const target = useLazyData(() => {
  home.getHotList()
})
// const target = ref(null)
// // 当整个区块处于可见状态 才发ajax
// onMounted(() => {
//   const {stop} = useIntersectionObserver(target.value,([{isIntersecting}]) => {
//   console.log('新鲜好物',isIntersecting );
//   // 可见
//   if(isIntersecting) {
//       //发送请求
//       home.getHotList()

//       // 停止监听
//       stop()
//    }
//   })
// })

</script>

<template>
    <div ref="target">
           <HomePanel  title="人气推荐" subTitle="人气爆款，不容错过">
      <ul class="goods-list" ref="target">
        <li v-for="item in home.hotGoodList" :key="item.id">
          <RouterLink :to="'/goods/' + item.id">
            <img
              v-lazy="item.picture"
              alt=""
            />
            <p class="name ellipsis">{{item.title}}</p>
            <p class="price">{{item.alt}}</p>
          </RouterLink>
        </li>
      </ul>
     </HomePanel>
    </div>
</template>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #fff;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      font-size: 18px;
      color: #999;
    }
  }
}
</style>